<?php

namespace App\Http\Requests;

use App\Models\Subject;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Request;

class SubjectUpdate extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize(Request $request)
    {
        $subject = Subject::where([
            'school_id' => $request->school_id,
            'campus_id' => $request->campus_id,
            'id' => $request->id
        ])->first();
        return $subject;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'subject_name' => 'sometimes|required|min:1|max:20',
            'remark' => 'sometimes|required|min:1|max:100',
            'status' => 'sometimes|required',
            'ks' => 'sometimes',
            'ks_value' => 'required_with:ks',
            'cz' => 'sometimes',
            'cz_value' => 'required_with:cz',
            'qx' => 'sometimes',
            'id' => 'required'
        ];
    }
}
